package com.jml.mycomponentscan;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;

/**
 * 本类初始化完毕后会执行InitializingBean这个接口
 * 其他非懒加载的类初始化完毕后都会执行前后置处理器BeanPostProcessor
 *
 */
@Component
public class Bean implements BeanPostProcessor, InitializingBean, BeanFactoryPostProcessor {

	protected final Log logger = LogFactory.getLog(getClass());

	Integer a = 10;

	public Bean() {
		System.out.println("构造方法初始化");
	}

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		System.out.println(beanName+"：执行postProcessBeforeInitialization ");
		if(bean instanceof Bean){
			Bean b = (Bean)bean;
			b.a=1000;
			System.out.println("a:"+this.a);
		}
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		System.out.println(beanName+"：执行postProcessAfterInitialization");
		if(bean instanceof Bean){
			Bean b = (Bean)bean;
			b.a=10000;
			System.out.println("a:"+this.a);
		}
		return bean;
	}


	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("执行afterPropertiesSet");
		this.a=100000;
		System.out.println("a:"+this.a);
	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		System.out.println("执行postProcessBeanFactory");
	}
}
